package wh.coach._json;

import java.util.Map;
import java.util.Objects;

import com.google.common.collect.ImmutableMap;

/**
 * @author hangwen
 * @date 2023/7/15
 */
public class Main {
    public static void main(String[] args) {
        //什么是序列化 和 反序列化
        //序列化：内存对象 -> 可传输的数据,什么叫可传输（IO）,什么样的数据可传输（字节） encode
        //反序列化：反之  decode

        //json,protobuf

        //json
        //1.性能较好；2.带有元信息；3.直接可读；4.天生跨平台
        //http restApi;redis

        //read write javaBean
        System.out.println("write read java bean");
        Person person = new Person(1L, "Jack", 20);

        String json = JsonHelper.writeAsString(person);
        System.out.println(json);

        Person decodedPerson = JsonHelper.readFromJson(json, Person.class);

        System.out.println("decodedPerson equals to person:" + (Objects.equals(person, decodedPerson)));

        //read write map
        System.out.println("write read map");
        Map<String, Object> map = ImmutableMap.of("id", 111111111111L, "name", "Jack", "age", 20);
        json = JsonHelper.writeAsString(map);
        System.out.println(json);

        Map<String, Object> decodedMap = JsonHelper.readFromJson(json, Map.class);

        System.out.println("decodedMap equals to map:" + (Objects.equals(map, decodedMap)));

        //1.理解上述所有代码
        //1.1 json
        //1.2 lombok 以及 什么是POJO 比如 装箱和原生类型
        //1.3 ImmutableMap.of
    }
}
